package com.gitee.feizns.quickstart.validation.validator;

import com.gitee.feizns.quickstart.validation.constraints.Enums;

import java.util.EnumSet;
import java.util.HashSet;
import java.util.Set;

/**
 * 保证匹配某值匹配枚举类型列表
 * @author feizns
 * @since 2023/2/7
 */
@SuppressWarnings({"unchecked", "rawtypes"})
public class EnumsConstraintValidator extends AbstractAllMatchConstraintValidator<Enums, Enum> {

    @Override
    protected Set<Enum> initializeValues(Enums constraintAnnotation) {
        Set<Enum> enums = new HashSet<>();
        for (Class<? extends Enum> enumType : constraintAnnotation.value())
            enums.addAll(EnumSet.allOf(enumType));
        return enums;
    }

}
